/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Administrator
 */
public class ChessScene extends Scene implements IGameDisplay {

    private static final int NUMBER_PIECES = 12;
    private static final int DELAY_TIME = 50;
    private static final int NUMBER_ROWS = 8;
    private static final int NUMBER_COLUMNS = 8;
    private static final int CHESS_BOARD_SIZE = 64;
    //chess type
    private static final int PAWN_WHITE = 0;
    private static final int ROCK_WHITE = 1;
    private static final int KNIGHT_WHITE = 2;
    private static final int BISHOP_WHITE = 3;
    private static final int QUEEN_WHITE = 4;
    private static final int KING_WHITE = 5;
    private static final int PAWN_BLACK = 6;
    private static final int ROCK_BLACK = 7;
    private static final int KNIGHT_BLACK = 8;
    private static final int BISHOP_BLACK = 9;
    private static final int QUEEN_BLACK = 10;
    private static final int KING_BLACK = 11;
    private static final int PIECE_VOID = -1;
    private static final int STATE_PIECE_MOVE = 1;
    private static final int PIECE_WHITE = 0;
    private static final int PIECE_BLACK = 1;
    private static final int NUMBER_VALID_MOVE = 32;
    private static final int NUMBER_PLAYER = 2;
    private static final int TIME_FOR_THINK = 120;
    private static final int DISTANCE_BETWEEN_LINE = 20;
    private static final int SUB_MENU_WIDTH = 128;
//    private static final int DIALOG_HEIGHT = 40;
    public static final long TIME_CHAT = 3000;
    //---------------------------------------------------------------------------
    private int backgroundX;
    private int backgroundY;
    private int chessBoxWidth;
    private int chessBoxHeight;
    private int chessBoxMarginTop;
    private int chessBoxMarginLeft;
    private int chessPieceSelected;
    private int srcMoveIndex;
    private int desMoveIndex;
    private int srcMoveX;
    private int srcMoveY;
    private int desMoveX;
    private int desMoveY;
    private int deltaMoveX;
    private int deltaMoveY;
    private int pieceMoveX;
    private int pieceMoveY;
    private int pieceMoveType;
    private int countPieceMoveStep;
    private int prevSelected;
    private int countCurseur;
    private int chessBorderWidth;
    private int chessBorderHeight;
    private int promotionIndex;
    private int promotionLocation;
    private boolean isPromotion;
    private boolean isSelectedSrcMove;
    private boolean isFinishGame;
//    private boolean isShowChatBox;
    private boolean isViewer;
    private boolean canEnterCastleLeft;
    private boolean canEnterCastleRight;
    private boolean isCheckMateWhite;
    private boolean isCheckMateBlack;
    private boolean enteringCastleLeft;
    private boolean enteringCastleRight;
    private boolean isMoveRockToCastle;
    private int chessBoardX;
    private int chessBoardY;
    private int chessPieceWidth;
    private int chessPieceHeight;
    private int playerId;
    private int gameTurn;
    private int chessMoveStep;
    private int winnerId;
//    private int countFrame;
    private int idCheckMated;
    private int numberPlayerReadys;
    private int numberPlayers;
    private int tableHostId;
    private int subMenuSelectedIndex;
    private int myPieceColor;
    private int maxPlayer;
    private int gameState;
    private int pieceColorSelect;
    private long lastTime;
    private int avatarWidth;
    private int avatarHeight;
    private int timeForThink;
    private int[] resultOrder;
    private int[] positionY;
    private int[] positionX;
    private int[] playerGendes;
    private int[] chessValidMove;
    private int[] chessBoardMapPieces;
    //image
//    private Image backgroundImage;
    private Image topBarImage;
//    private Image loadingImage;
    private Image chessBoardImage;
    private Image chessPieceImageArray;
    private Image winImage;
    private Image loseImage;
    private Image bottomBarImage;
    private Image avatarImage;
    private Image boxColorImages;
    private Image drawResultImage;
    //
    private CustomTextBox chatBox;
    private ShortShowBox[] messengerBoxs;
    private boolean isHasChessMap;
    private FlyString[] moneyFlyStrings;
    //-------------------------------------------------------------------------
//    private boolean isBack;

    public ChessScene(MainCanvas parent) {
        super(parent);
        initValue();
        initObject();
    }

    private void intChessBoardForViewer() {
        if (gameData.chessMapData != null) {
            String[] mapData = gameData.chessMapData;
            for (int i = 1, l = mapData.length; i < l - 1; i++) {
                int position = Integer.parseInt(mapData[i + 1]);
                // Debug.d("i:" + i + ",pos:" + position + ",piece:" + mapData[i]);
                // printPieceName(Integer.parseInt(mapData[i]));
                chessBoardMapPieces[position] = Integer.parseInt(mapData[i]);
                i += 1;
            }
            isHasChessMap = true;
        } else {
            isHasChessMap = false;
        }
    }

    private void initValue() {
        timeForThink = TIME_FOR_THINK;
        backgroundX = 0;
        backgroundY = 0;
        chessMoveStep = 10;
        chessBorderWidth = 15;
        chessBorderHeight = 15;
        numberPlayers = gameData.getNumberPlayers();
        playerId = gameData.getPlayerId();
        tableHostId = gameData.getTableHostId();
        if (playerId == tableHostId) {
            myPieceColor = PIECE_WHITE;
        } else {
            myPieceColor = PIECE_BLACK;
        }
        Debug.d("my piece color :" + myPieceColor + ",player id:" + playerId);
        maxPlayer = gameData.getMaxPlayer();
        isViewer = (gameData.getMyViewId() < maxPlayer ? false : true);
        Debug.d("isViewer :" + isViewer);
        if (isViewer) {
            playerId = tableHostId;
        }
        chessBoardMapPieces = new int[64];
        for (int i = 0; i < 64; i++) {
            chessBoardMapPieces[i] = PIECE_VOID;
        }
        if (!isViewer) {
            setupChessBoard();

        } else {
            intChessBoardForViewer();
        }
        canEnterCastleLeft = canEnterCastleRight = true;
        chessValidMove = new int[32];
        for (int i = 0; i < NUMBER_VALID_MOVE; i++) {
            chessValidMove[i] = -1;
        }
        gameData.setGameDisplay(this);
    }

    private void initObject() {
        try {
            initImage();
            initMessengerBox();
            initCustomBox();
            initPositon();
        } catch (IOException ex) {
        }
    }

    private void initMessengerBox() {
        messengerBoxs = new ShortShowBox[4];
        for (int i = 0; i < 4; i++) {
            messengerBoxs[i] = new ShortShowBox();
        }
        moneyFlyStrings = new FlyString[4];
        for (int i = 0; i < 4; i++) {
            moneyFlyStrings[i] = new FlyString(FlyString.FLY_VERTICAL, PiPoDesigner.COLOR_YELOW);
        }
    }

    private void initCustomBox() {
        chatBox = new CustomTextBox(PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, false, keyPad);
        chatBox.setFocus(true);
        chatBox.setShowTypeInput(false);
    }

    private void initImage() throws IOException {
        chessBoardImage = Utils.loadImage("covua_board.png");
        chessBoardX = (canvasWidth - chessBoardImage.getWidth()) / 2;
        chessBoardY = (canvasHeight - chessBoardImage.getHeight()) / 2;
        chessPieceImageArray = Utils.loadImage("chess_pieces.png");
        chessPieceWidth = chessPieceImageArray.getWidth() / 6;
        chessPieceHeight = chessPieceImageArray.getHeight() / 2;
        chessBoxWidth = (chessBoardImage.getWidth() - 2 * chessBorderWidth) / NUMBER_COLUMNS;
        chessBoxHeight = (chessBoardImage.getHeight() - 2 * chessBorderHeight) / NUMBER_ROWS;
        chessBoxMarginLeft = 2;
        chessBoxMarginTop = -chessPieceHeight / 2 + 2;
        drawResultImage = Utils.loadImage("hoa.png");
        topBarImage = library.getTopBarImage();
        bottomBarImage = library.getBottomBarImage();
        winImage = Utils.loadImage("thang.png");
        loseImage = Utils.loadImage("thua.png");
        boxColorImages = Utils.loadImage("o_di.png");
        avatarImage = library.getAvatar();
    }

    private void initPositon() {
        avatarWidth = avatarImage.getWidth() >> 2;
        avatarHeight = avatarImage.getHeight();
        resultOrder = new int[maxPlayer];
        positionX = new int[4];
        positionX[0] = positionX[2] = canvasWidth / 2 - avatarWidth / 2;
        positionX[3] = leftScreen + 10;
        positionX[1] = canvasWidth - 10 - avatarWidth;
        positionY = new int[4];
        positionY[0] = canvasHeight - avatarHeight - 10;
        positionY[1] = positionY[3] = canvasHeight / 2 - avatarHeight / 2;
        positionY[2] = topScreen + 10;
    }

    public void dispose() {
        resultOrder = null;
        positionY = null;
        positionX = null;
        playerGendes = null;
        chessValidMove = null;
        chessBoardMapPieces = null;
        //image
//        backgroundImage = null;
        topBarImage = null;
        loadingImage = null;
        chessBoardImage = null;
        chessPieceImageArray = null;
        winImage = null;
        loseImage = null;
        bottomBarImage = null;
        boxColorImages = null;
        avatarImage = null;
        drawResultImage = null;
        moneyFlyStrings = null;
        //
        chatBox = null;
        messengerBoxs = null;
        gameData.disposeChessMap();
        super.dispose();

    }

    public void setListSubMenu() {
        if (!isViewer) {
            subMenu.setList(new String[]{"Rời bàn", "Đề nghị hòa", "Nhận thua"});
        } else {
            subMenu.setList(null);
        }
    }

    private void setupChessBoard() {
        if (myPieceColor == PIECE_WHITE) {
            for (int i = 0; i < NUMBER_COLUMNS; i++) {
                chessBoardMapPieces[i + 48] = PAWN_WHITE;
                chessBoardMapPieces[i + 8] = PAWN_BLACK;
            }
            chessBoardMapPieces[0] = ROCK_BLACK;
            chessBoardMapPieces[1] = KNIGHT_BLACK;
            chessBoardMapPieces[2] = BISHOP_BLACK;
            chessBoardMapPieces[3] = QUEEN_BLACK;
            chessBoardMapPieces[4] = KING_BLACK;
            chessBoardMapPieces[5] = BISHOP_BLACK;
            chessBoardMapPieces[6] = KNIGHT_BLACK;
            chessBoardMapPieces[7] = ROCK_BLACK;
            chessBoardMapPieces[56] = ROCK_WHITE;
            chessBoardMapPieces[57] = KNIGHT_WHITE;
            chessBoardMapPieces[58] = BISHOP_WHITE;
            chessBoardMapPieces[59] = QUEEN_WHITE;
            chessBoardMapPieces[60] = KING_WHITE;
            chessBoardMapPieces[61] = BISHOP_WHITE;
            chessBoardMapPieces[62] = KNIGHT_WHITE;
            chessBoardMapPieces[63] = ROCK_WHITE;

        } else {
            for (int i = 0; i < NUMBER_COLUMNS; i++) {
                chessBoardMapPieces[i + 48] = PAWN_BLACK;
                chessBoardMapPieces[i + 8] = PAWN_WHITE;
            }
            chessBoardMapPieces[56] = ROCK_BLACK;
            chessBoardMapPieces[57] = KNIGHT_BLACK;
            chessBoardMapPieces[58] = BISHOP_BLACK;
            chessBoardMapPieces[59] = KING_BLACK;
            chessBoardMapPieces[60] = QUEEN_BLACK;
            chessBoardMapPieces[61] = BISHOP_BLACK;
            chessBoardMapPieces[62] = KNIGHT_BLACK;
            chessBoardMapPieces[63] = ROCK_BLACK;
            chessBoardMapPieces[0] = ROCK_WHITE;
            chessBoardMapPieces[1] = KNIGHT_WHITE;
            chessBoardMapPieces[2] = BISHOP_WHITE;
            chessBoardMapPieces[3] = KING_WHITE;
            chessBoardMapPieces[4] = QUEEN_WHITE;
            chessBoardMapPieces[5] = BISHOP_WHITE;
            chessBoardMapPieces[6] = KNIGHT_WHITE;
            chessBoardMapPieces[7] = ROCK_WHITE;

        }
        chessPieceSelected = 52;
        gameTurn = 0;
        isHasChessMap = true;
    }
//--------------------------------------------------------------------------------

    private void doWhenTimeExpired() {
        //test
        //  nextTurn();
        isLoading = true;
        if (gameTurn == playerId) {
            Request.nextTurnChess();
        }
        parent.repaint();

    }

    public void clockCount() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastTime > 1000) {
            timeForThink--;
            lastTime = currentTime;
            if (timeForThink == 0) {
                doWhenTimeExpired();
            }
            parent.repaint();
        }
    }

    private void doMovePiece() {
        pieceMoveX += deltaMoveX / chessMoveStep;
        pieceMoveY += deltaMoveY / chessMoveStep;
        Debug.d("do move piece :" + countPieceMoveStep);
        countPieceMoveStep += 1;
        parent.repaint();
        if (countPieceMoveStep == chessMoveStep) {
            doWhenFinishMove();
        }
    }

    private void doWhenFinishMove() {
        countPieceMoveStep = 0;
        gameState = 0;
        chessBoardMapPieces[desMoveIndex] = pieceMoveType;
        parent.repaint();
        if (isCheckMate()) {
            Request.checkMate(gameTurn);
            switchMessengerBox(0, "Chiếu tướng");
            parent.repaint();
        }
        if (!isMoveRockToCastle) {
            nextTurn();
        }
//            Debug.d("is move rock :" + isMoveRockToCastle);
//            Debug.d("nhap thanh phai move:" + enteringCastleRight);
//            Debug.d("nhap thanh trai move:" + enteringCastleLeft);
        if (isMoveRockToCastle && (enteringCastleLeft || enteringCastleRight)) {
            enteringCastleLeft = false;
            enteringCastleRight = false;
            isMoveRockToCastle = false;
        }
//        Debug.d("des move index :" + desMoveIndex);
//        Debug.d("piece move ty pe :" + pieceMoveType);
//        Debug.d("my color :" + myPieceColor);
        if ((pieceMoveType == PAWN_BLACK && myPieceColor == PIECE_BLACK) || (pieceMoveType == PAWN_WHITE && myPieceColor == PIECE_WHITE)) {
            if (desMoveIndex / 8 == 0) {
                promotionLocation = desMoveIndex;
                isPromotion = true;
            }
            return;
        }
//        Debug.d("piece move type:" + pieceMoveType);
        if ((enteringCastleLeft || enteringCastleRight) && (pieceMoveType == KING_BLACK || pieceMoveType == KING_WHITE)) {
            moveRockToCastle();
            return;
        }
    }

    private void nextTurn() {
        if (Debug.isTest) {
            return;
        }
        if (desMoveIndex < 0 || desMoveIndex > CHESS_BOARD_SIZE - 1) {
            desMoveIndex = 45;
        }
        chessValidMove[0] = -1;
        chessPieceSelected = desMoveIndex;
        // Debug.d("check mate:" + isCheckMate());

        gameTurn = (++gameTurn) % NUMBER_PLAYER;
        timeForThink = TIME_FOR_THINK;
        Debug.d("game turn :" + gameTurn);
        parent.repaint();
    }

    private boolean isCheckMate() {
        generateValidMove();
        isCheckMateBlack = isCheckMateWhite = false;
        for (int i = 0; i < NUMBER_VALID_MOVE; i++) {
            int validMove = chessValidMove[i];
            if (validMove == -1) {
                break;
            } else {
                // Debug.d("valid move:" + chessBoardMapPieces[validMove]);
                //  Debug.d("piece color control:" + pieceColorSelect);
                int piece = chessBoardMapPieces[validMove];
                if (piece == KING_BLACK && myPieceColor == PIECE_WHITE && gameTurn == tableHostId) {
                    isCheckMateBlack = true;
                    return true;
                }
                if (piece == KING_WHITE && myPieceColor == PIECE_BLACK && gameTurn != tableHostId) {
                    isCheckMateWhite = true;
                    return true;
                }
            }
        }
        return false;
    }

    private void moveRockToCastle() {
        isMoveRockToCastle = true;
        Debug.d("game turn :" + gameTurn);
        Debug.d("player id :" + playerId);
        if (enteringCastleLeft) {
            if (myPieceColor == PAWN_WHITE) {
                if (gameTurn != playerId) {
                    doStepMovePiece(playerId, 56 / 8, 56 % 8, 59 / 8, 59 % 8);
                } else {
                    doStepMovePiece(1 - playerId, 0, 0, 0, 3);
                }
            } else {
                if (gameTurn != playerId) {
                    doStepMovePiece(playerId, 56 / 8, 56 % 8, 58 / 8, 58 % 8);
                } else {
                    doStepMovePiece(1 - playerId, 0, 0, 0, 2);
                }

            }
        }
        if (enteringCastleRight) {
            if (myPieceColor == PAWN_WHITE) {
                if (gameTurn != playerId) {
                    doStepMovePiece(playerId, 63 / 8, 63 % 8, 61 / 8, 61 % 8);
                } else {
                    doStepMovePiece(1 - playerId, 0, 7, 0, 5);
                }
            } else {
                if (gameTurn != playerId) {
                    doStepMovePiece(playerId, 63 / 8, 63 % 8, 60 / 8, 60 % 8);
                } else {
                    doStepMovePiece(1 - playerId, 0, 7, 0, 4);
                }
            }
        }
    }

    public void doLoop() {
        clockCount();
        switch (gameState) {
            case STATE_PIECE_MOVE:
                try {
                    doMovePiece();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                break;
            default:
                break;
        }
        if (isShowChatBox && countFrame % 4 == 0) {
            chatBox.run();
            parent.repaint();
            return;
        }
        for (int i = 0; i < 4; i++) {
            if (messengerBoxs[i].isShow) {
                messengerBoxs[i].run();
                parent.repaint();
            }
        }
        for (int i = 0; i < 2; i++) {
            if (moneyFlyStrings[i].isShow) {
                moneyFlyStrings[i].run();
                parent.repaint();
            }
        }
    }

    private void paintMoneyChange(Graphics g) {
        moneyFlyStrings[0].paint(g);
        moneyFlyStrings[1].paint(g);
//        moneyFlyStrings[2].paint(g);
//        moneyFlyStrings[3].paint(g);
    }

    public void paintComponents(Graphics g) {
        if (!isViewer || (isViewer && !isFinishGame)) {
            if (isHasChessMap) {
                paintChessBoard(g);
            } else {
                PiPoDesigner.drawString(g, "Trận đấu chưa bắt đầu", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, 10, topBarImage.getHeight() + 20);
            }
        }
        paintBarMenu(g);
        paintMessageChat(g);
        if (isShowChatBox) {
            chatBox.paint(g, leftScreen + 10, canvasHeight - 45, canvasWidth - 20, 20);
        }
        if (isFinishGame) {
            if (!isViewer) {
                paintResult(g);
            } else {
                paintViewResult(g);
            }
        }
        switch (gameState) {
            case STATE_PIECE_MOVE:
                paintPieceMove(g);
                break;
            default:
                break;
        }

        if (!isFinishGame && !isViewer && !isShowChatBox) {
            paintClock(g);
        }

        if (isPromotion) {
            paintPromotion(g);
        }
        paintMoneyChange(g);

    }

    private void paintPieceMove(Graphics g) {
        Utils.drawFrame(g, chessPieceImageArray, pieceMoveX, pieceMoveY, pieceMoveType % 6, pieceMoveType / 6, chessPieceWidth, chessPieceHeight);
    }

    private void paintPromotion(Graphics g) {
        int padding = 10;
        int promotionFrameHeight = chessPieceHeight + 10;
        int promotionFrameWidth = (chessPieceWidth + padding) * 4 + padding;
        int leftPromotionFrame = canvasWidth / 2 - promotionFrameWidth / 2;
        int topPromotionFrame = canvasHeight / 2 - promotionFrameHeight / 2;
        g.setColor(0xffffff);
        g.drawRoundRect(leftPromotionFrame, topPromotionFrame, promotionFrameWidth, promotionFrameHeight, 7, 7);
        g.setColor(0x343941);
        g.fillRoundRect(leftPromotionFrame + 1, topPromotionFrame + 1, promotionFrameWidth - 1, promotionFrameHeight - 1, 7, 7);
        g.setColor(0xff0000);
        g.drawRoundRect(leftPromotionFrame + promotionIndex * (padding + chessPieceWidth) + padding, topPromotionFrame + 5, chessPieceWidth, chessPieceHeight, 7, 7);
        if (myPieceColor == PIECE_WHITE) {
            for (int i = 0; i < 4; i++) {
                Utils.drawFrame(g, chessPieceImageArray, leftPromotionFrame + i * (padding + chessPieceWidth) + padding, topPromotionFrame + 5, i + 1, 0, chessPieceWidth, chessPieceHeight);
            }
        } else {
            for (int i = 0; i < 4; i++) {
                Utils.drawFrame(g, chessPieceImageArray, leftPromotionFrame + i * (padding + chessPieceWidth) + padding, topPromotionFrame + 5, i + 1, 1, chessPieceWidth, chessPieceHeight);
            }
        }
    }

    private void paintClock(Graphics g) {
        int minute = timeForThink / 60;
        int seconde = timeForThink % 60;

        if (seconde >= 10) {
            PiPoDesigner.drawString(g, minute + ":" + seconde, PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                    canvasWidth / 2 - 20, canvasHeight - 25);
        } else {
            PiPoDesigner.drawString(g, minute + ":0" + seconde, PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                    canvasWidth / 2 - 20, canvasHeight - 25);
        }
    }

    private void paintResult(Graphics g) {
        if (resultOrder[playerId] != 2) {
            if (winnerId == playerId) {
                g.drawImage(winImage, canvasWidth / 2 - winImage.getWidth() / 2, canvasHeight / 2 - winImage.getHeight() / 2, 0);
            } else {
                g.drawImage(loseImage, canvasWidth / 2 - loseImage.getWidth() / 2, canvasHeight / 2 - winImage.getHeight() / 2, 0);
            }
        } else {
            g.drawImage(drawResultImage, canvasWidth / 2 - loseImage.getWidth() / 2, canvasHeight / 2 - winImage.getHeight() / 2, 0);
        }
    }

    private void paintViewResult(Graphics g) {
        paintResult(g, 0, playerId);
        paintResult(g, (1 - playerId + 4) % 4, 1 - playerId);
    }

    private void paintResult(Graphics g, int posId, int id) {
        if (!isFinishGame) {
            return;
        }
        int bottomHeight = bottomBarImage.getHeight();
//?        g.drawImage(boyAvatarImage, positionX[posId], positionY[posId] - bottomHeight, 0);
        Utils.drawFrame(g, avatarImage, positionX[posId], positionY[posId] - bottomHeight, gameData.avatarIds[id], 0, avatarWidth, avatarHeight);
        int x = 0;
        int y = 0;
        switch (posId) {
            case 0:
                x = positionX[posId] + 30;
                y = positionY[posId];
                // name
                PiPoDesigner.drawString(g, gameData.playerName[id], PiPoDesigner.COLOR_BLACK,
                        PiPoDesigner.COLOR_WHITE, positionX[posId] + avatarWidth, positionY[posId]);
                break;
            case 1:
                x = positionX[posId] - 30;
                y = positionY[posId];
                // name
                PiPoDesigner.drawString(g, gameData.playerName[id], PiPoDesigner.COLOR_BLACK,
                        PiPoDesigner.COLOR_WHITE, canvasWidth - PiPoDesigner.stringWidth(gameData.playerName[id]) - 5, positionY[posId] + 10);
                break;
            case 2:
                x = positionX[posId] + 20;
                y = positionY[posId];
                break;
            case 3:
                x = positionX[posId] + 20;
                y = positionY[posId] + 20;
                break;
        }
        if (resultOrder[id] == 0) {
            g.drawImage(winImage, x, y - bottomHeight, 0);
        } else if (resultOrder[id] == 1) {
            g.drawImage(loseImage, x - 20, y - bottomHeight, 0);
        } else if (resultOrder[id] == 2) {
            g.drawImage(drawResultImage, x - 20, y - bottomHeight, 0);
        }
    }

    private void paintMessageChat(Graphics g) {
        messengerBoxs[0].paint(g);
        messengerBoxs[1].paint(g);
        messengerBoxs[2].paint(g);
        messengerBoxs[3].paint(g);

    }

    protected void paintBarMenu(Graphics g) {
        if (screenMode == SCREEN_PORTRAIT) {
            g.drawImage(topBarImage, leftScreen, topScreen, 0);
            g.drawImage(bottomBarImage, leftScreen, canvasHeight - bottomBarImage.getHeight(), 0);
        }
        if (!isViewer && screenMode == SCREEN_PORTRAIT) {
            if (gameTurn == playerId) {
                PiPoDesigner.drawString(g, "Lượt đi của bạn", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                        canvasWidth / 2 - PiPoDesigner.stringWidth("Lượt đi của bạn") / 2, 5);
            } else {
                PiPoDesigner.drawString(g, "Lượt đi của đối thủ", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                        canvasWidth / 2 - PiPoDesigner.stringWidth("Lượt đi của đối thủ") / 2, 5);
            }
        }
        if (isFinishGame && !isViewer) {
            PiPoDesigner.drawString(g, "Tiếp tục", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth / 2 - 30, canvasHeight - 25);
        }
        if (isViewer) {
            PiPoDesigner.drawString(g, "Đang xem", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth / 2 - 30, canvasHeight - 25);
        }
        if (isShowChatBox) {
            PiPoDesigner.drawString(g, "Đóng", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, leftScreen + 5, canvasHeight - 25);
            PiPoDesigner.drawString(g, "Xóa", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth - 30, canvasHeight - 25);
            PiPoDesigner.drawString(g, "Gửi", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth / 2 - 20, canvasHeight - 25);
            return;
        } else {
            if (!isViewer) {
                PiPoDesigner.drawString(g, "Menu", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, leftScreen + 5, canvasHeight - 25);
            }
            if (!isShowSubMenu) {
                PiPoDesigner.drawString(g, "Thoát", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth - 40, canvasHeight - 25);
            } else {
                PiPoDesigner.drawString(g, "Đóng", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth - 40, canvasHeight - 25);
            }
        }
    }
    private void paintChessBoard(Graphics g) {
        g.drawImage(chessBoardImage, chessBoardX, chessBoardY, 0);
        int columnSelected = chessPieceSelected % NUMBER_ROWS;
        int rowSelected = chessPieceSelected / NUMBER_COLUMNS;
        if (isSelectedSrcMove && gameTurn == playerId && !isViewer) {
            // draw valid move
            g.setColor(0xffffff);
            Utils.drawFrame(g, boxColorImages, srcMoveX - chessBoxMarginLeft, srcMoveY - chessBoxMarginTop,
                    0, 0, boxColorImages.getWidth() / 3, boxColorImages.getHeight());
            for (int i = 0; i < NUMBER_VALID_MOVE; i++) {
                int validMove = chessValidMove[i];
                int validMoveX = getChessBoxX(validMove);
                int validMoveY = getChessBoxY(validMove);
                if (validMove == -1) {
                    break;
                } else {
                    if (chessBoardMapPieces[validMove] == PIECE_VOID) {
                        // g.drawImage(boxColorImages[2], validMoveX - chessBoxMarginLeft, validMoveY - chessBoxMarginTop, 0);
                        Utils.drawFrame(g, boxColorImages, validMoveX - chessBoxMarginLeft, validMoveY - chessBoxMarginTop, 2, 0,
                                boxColorImages.getWidth() / 3, boxColorImages.getHeight());
                    } else {
                        // g.drawImage(boxColorImages[1], validMoveX - chessBoxMarginLeft, validMoveY - chessBoxMarginTop, 0);
                        Utils.drawFrame(g, boxColorImages, validMoveX - chessBoxMarginLeft, validMoveY - chessBoxMarginTop, 1, 0,
                                boxColorImages.getWidth() / 3, boxColorImages.getHeight());
                    }
                }
            }
        }
        // draw piece on board
        if (gameTurn == playerId && !isViewer) {
            g.setColor(0xff0000);
            g.drawRoundRect(chessBoardX + chessBorderWidth + columnSelected * chessBoxWidth, chessBoardY + chessBorderHeight + rowSelected * chessBoxHeight, chessBoxWidth, chessBoxHeight, 3, 3);
        }
        for (int i = 0, l = chessBoardMapPieces.length; i < l; i++) {
            int piece = chessBoardMapPieces[i];
            if (piece != -1) {
                int columnIndex = i % NUMBER_ROWS;
                int rowIndex = i / NUMBER_COLUMNS;

                Utils.drawFrame(g, chessPieceImageArray, chessBoardX + chessBorderWidth + columnIndex * chessBoxWidth + chessBoxMarginLeft,
                        chessBoardY + chessBorderHeight + rowIndex * chessBoxHeight + chessBoxMarginTop,
                        piece % 6, piece / 6, chessPieceWidth, chessPieceHeight);
            }
        }
        //paint move piece


    }

    private int getChessBoxX(int index) {
        int column = index % NUMBER_COLUMNS;
        int row = index / NUMBER_ROWS;
        return chessBoardX + column * chessBoxWidth + chessBoxMarginLeft + chessBorderWidth;
    }

    private int getChessBoxY(int index) {
        int column = index % NUMBER_COLUMNS;
        int row = index / NUMBER_ROWS;
        return chessBoardY + row * chessBoxHeight + chessBoxMarginTop + chessBorderHeight;
    }

    private int getChessColorAtPosition(int index) {
        int piece = chessBoardMapPieces[index];
        Debug.d("piece:" + piece);
        if (piece == PIECE_VOID) {
            return PIECE_VOID;
        }
        if (piece > KING_WHITE) {
            return PIECE_BLACK;
        }
        return PIECE_WHITE;
    }
//-------------------------------------------------------------------------------

    public void doKeyLeft() {
        if (isPromotion) {
            promotionIndex--;
            if (promotionIndex < 0) {
                promotionIndex = 3;
            }
            parent.repaint();
            return;
        }
        chessPieceSelected--;
        if (chessPieceSelected % NUMBER_ROWS == NUMBER_ROWS - 1) {
            chessPieceSelected = chessPieceSelected + NUMBER_ROWS;
        }
        parent.repaint();
    }

    public void doKeyRight() {
        if (isPromotion) {
            promotionIndex = (++promotionIndex) % 4;
            parent.repaint();
            return;
        }
        chessPieceSelected++;
        if (chessPieceSelected % NUMBER_ROWS == 0) {
            chessPieceSelected = chessPieceSelected - NUMBER_ROWS;
        }
        parent.repaint();
    }

    public void doKeyPound() {
    }

    protected void doKeyUpRemain() {
        chessPieceSelected -= NUMBER_ROWS;
        if (chessPieceSelected < 0) {
            chessPieceSelected = CHESS_BOARD_SIZE + chessPieceSelected;
        }
        parent.repaint();
    }

    protected void doKeyDownRemain() {

        chessPieceSelected += NUMBER_ROWS;
        if (chessPieceSelected > CHESS_BOARD_SIZE) {
            chessPieceSelected = chessPieceSelected % NUMBER_COLUMNS;
        }
        parent.repaint();
    }

    protected void doSoftKeyLeftRemain() {
        if (isShowChatBox) {
            isShowChatBox = false;
            chatBox.setText("");
            parent.repaint();
            return;
        }
    }

    protected void doSoftKeyRightRemain() {
        if (isShowChatBox) {
            chatBox.doSoftKeyRight();
            return;
        }
        isLoading = true;
        Request.exitTable();
        parent.repaint();

    }

    protected void reponseQuestion(int result) {
        if (result == 1) {
            Request.reponseDrawAsk(1);
            isFinishGame = true;
            resultOrder[playerId] = 2;
            parent.repaint();
        } else {
            Request.reponseDrawAsk(0);
            parent.repaint();
        }

    }

    public void switchMessengerBox(int posId, String text) {
        switch (posId) {
            case 0:
                messengerBoxs[0].setText(text);
                messengerBoxs[0].setPosition(canvasWidth / 2 - messengerBoxs[0].getBoxWidth() / 2, positionY[0]);
                break;
            case 1:
                messengerBoxs[1].setText(text);
                messengerBoxs[1].setPosition(canvasWidth - 10 - messengerBoxs[1].getBoxWidth(), positionY[1]);
                break;
            case 2:
                messengerBoxs[2].setText(text);
                messengerBoxs[2].setPosition(canvasWidth / 2 - messengerBoxs[2].getBoxWidth() / 2, positionY[2]);
                break;
            case 3:
                messengerBoxs[3].setText(text);
                messengerBoxs[3].setPosition(positionX[3], positionY[3]);
                break;
        }
        messengerBoxs[posId].show(1000);
    }

    protected void doKeyCenterRemain() {
        if (isShowChatBox && !isViewer) {
            String messageText = chatBox.getText();
            if (messageText.length() == 0) {
                isShowChatBox = false;
                parent.repaint();
                return;
            }
            if (messageText.length() > 25) {
                dialogString = "Số kí tự chat không vượt quá 25";
                parent.repaint();
                return;
            }
            switchMessengerBox(0, messageText);
            isShowChatBox = false;
            Request.chat(chatBox.getText());
            chatBox.setText("");
            parent.repaint();
            return;
        }
        if (isPromotion) {
            setPiecePromotion();
            return;
        }

        if (isFinishGame && !isViewer) {
            Request.finishChessGame(winnerId);
            Request.changeReadyState(0);
            isLoading = true;
//            for (int i = 0; i < numberPlayers; i++) {
//                gameData.readyStates[i] = 0;
//            }
            showWaitingRoom();
            parent.repaint();
            return;
        }
        if (gameTurn == playerId) {
            if (!isSelectedSrcMove) {
                selectSourcePosition();
            } else {
                selectDestPosition();
            }
            return;
        }


    }

    private void generateValidMove() {
        int piece = chessBoardMapPieces[chessPieceSelected];
        // reset valid move
        for (int i = 0; i < chessValidMove.length; i++) {
            chessValidMove[i] = -1;
        }
        switch (piece) {
            case PAWN_BLACK:
            case PAWN_WHITE:
                generatePawnMove();
                break;
            case ROCK_BLACK:
            case ROCK_WHITE:
                generateRockMove();
                break;
            case KNIGHT_BLACK:
            case KNIGHT_WHITE:
                generateKnightMove();
                break;
            case BISHOP_BLACK:
            case BISHOP_WHITE:
                generateBishopMove();
                break;
            case QUEEN_BLACK:
            case QUEEN_WHITE:
                generateQueenMove();
                break;
            case KING_BLACK:
            case KING_WHITE:
                generateKingMove();
                break;
            default:
                break;
        }
    }

    private void generateKingMove() {
        int countValidMove = 0;
        //check nuoc di ben trai
        int index = chessPieceSelected - 1;
        if (index % NUMBER_COLUMNS > 0 && pieceColorSelect != getChessColorAtPosition(index)) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        //check cheo trai
        index = chessPieceSelected - NUMBER_COLUMNS - 1;
        if (index > 0
                && pieceColorSelect != getChessColorAtPosition(index)
                && index % NUMBER_COLUMNS > 0) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        //check di len
        index = chessPieceSelected - NUMBER_COLUMNS;
        if (index > 0
                && pieceColorSelect != getChessColorAtPosition(index)) {

            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        //cheo phai

        index = chessPieceSelected - NUMBER_COLUMNS + 1;
        if (index > 0
                && pieceColorSelect != getChessColorAtPosition(index)
                && chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 1) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        //ben phai
        index = chessPieceSelected + 1;
        if (chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 1
                && pieceColorSelect != getChessColorAtPosition(index)) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        //di xuong
        index = chessPieceSelected + NUMBER_COLUMNS;
        if (index < 64 && pieceColorSelect != getChessColorAtPosition(index)) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        // xuoong  cheo phai
        index = chessPieceSelected + NUMBER_COLUMNS + 1;
        if (index < 64 && pieceColorSelect != getChessColorAtPosition(index) && index != NUMBER_COLUMNS - 1) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        index = chessPieceSelected + NUMBER_COLUMNS - 1;
        if (index < 64 && pieceColorSelect != getChessColorAtPosition(index) && index != 0) {
            chessValidMove[countValidMove] = index;
            countValidMove++;
        }
        if (myPieceColor == PIECE_WHITE) {
            if (canEnterCastleLeft && !isCheckMateWhite) {
                if (!isBlocked(57, 59)) {
                    chessValidMove[countValidMove] = 58;
                    countValidMove++;
                }
            }
            if (canEnterCastleRight && !isCheckMateWhite) {
                if (!isBlocked(61, 62)) {
                    chessValidMove[countValidMove] = 62;
                    countValidMove++;
                }
            }
        } else {
            if (canEnterCastleLeft && !isCheckMateBlack) {
                if (!isBlocked(57, 58)) {
                    chessValidMove[countValidMove] = 57;
                    countValidMove++;
                }
            }
            if (canEnterCastleRight && !isCheckMateBlack) {
                if (!isBlocked(60, 62)) {
                    chessValidMove[countValidMove] = 61;
                    countValidMove++;
                }
            }

        }

    }

    private void selectSourcePosition() {
        Debug.d("select source game turn :" + gameTurn);
        Debug.d("select source player id :" + playerId);
        if (chessBoardMapPieces[chessPieceSelected] == PIECE_VOID) {
            return;
        }
        if (gameTurn != playerId) {
            return;
        }
        pieceColorSelect = getChessColorAtPosition(chessPieceSelected);
        Debug.d("piece select :" + pieceColorSelect);
        Debug.d("my piece color :" + myPieceColor);
        if (pieceColorSelect != myPieceColor) {
            return;
        }
        generateValidMove();
        isSelectedSrcMove = true;
        srcMoveIndex = chessPieceSelected;
        srcMoveX = getChessBoxX(srcMoveIndex);
        srcMoveY = getChessBoxY(srcMoveIndex);
        parent.repaint();
    }

    private boolean isBlocked(int start, int end) {
        for (int i = start; i <= end; i++) {
            if (chessBoardMapPieces[i] != PIECE_VOID) {
                return true;
            }
        }
        return false;
    }

    private void generateQueenMove() {
        //TODO: remove duplicate code with rock and bishop
        int countValidMove = 0;
        //upper left
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected - NUMBER_COLUMNS * i - i;
            if (index < 0) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //lower left
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected + NUMBER_COLUMNS * i - i;
            if (index >= CHESS_BOARD_SIZE) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //lower right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected + NUMBER_COLUMNS * i + i;
            if (index > CHESS_BOARD_SIZE) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        // upper right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected - NUMBER_COLUMNS * i + i;
            if (index < 0) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected - i;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //check right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected + i;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //check up
        for (int i = 1, l = chessPieceSelected / NUMBER_ROWS; i <= l; i++) {
            int index = chessPieceSelected - i * NUMBER_COLUMNS;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        // check down
        for (int i = 1, l = NUMBER_ROWS - chessPieceSelected / NUMBER_ROWS; i < l; i++) {
            int index = chessPieceSelected + i * NUMBER_COLUMNS;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }

    }

    private void generateBishopMove() {
        int countValidMove = 0;
        //upper left
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected - NUMBER_COLUMNS * i - i;
            if (index < 0) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //lower left
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected + NUMBER_COLUMNS * i - i;
            if (index >= CHESS_BOARD_SIZE) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //lower right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected + NUMBER_COLUMNS * i + i;
            if (index >= CHESS_BOARD_SIZE) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        // upper right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected - NUMBER_COLUMNS * i + i;
            if (index < 0) {
                break;
            }
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (pieceColorSelect == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }

    }

    private void generateKnightMove() {
        //follow clockwise
        int countValidMove = 0;
        int index;
        int piece;
        index = chessPieceSelected + NUMBER_COLUMNS + 2;
        if (index < CHESS_BOARD_SIZE) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 2) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected + NUMBER_COLUMNS * 2 + 1;
        if (index < CHESS_BOARD_SIZE) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 1) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected + NUMBER_COLUMNS * 2 - 1;
        if (index < CHESS_BOARD_SIZE) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS > 0) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected + NUMBER_COLUMNS - 2;
        if (index < CHESS_BOARD_SIZE) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS > 1) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }

        index = chessPieceSelected - NUMBER_COLUMNS - 2;
        if (index > 0) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS > 1) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected - NUMBER_COLUMNS * 2 - 1;
        if (index > 0) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS > 0) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected - NUMBER_COLUMNS * 2 + 1;
        if (index > 0) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 1) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
        index = chessPieceSelected - NUMBER_COLUMNS + 2;
        if (index > 0) {
            if ((chessBoardMapPieces[index] == PIECE_VOID
                    || chessBoardMapPieces[index] != PIECE_VOID && pieceColorSelect != getChessColorAtPosition(index))
                    && chessPieceSelected % NUMBER_COLUMNS < NUMBER_COLUMNS - 2) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            }
        }
    }

    private void generateRockMove() {
        //TODO: write function reduce code
        //check left
        int countValidMove = 0;
        for (int i = 1, l = chessPieceSelected % NUMBER_COLUMNS; i <= l; i++) {
            int index = chessPieceSelected - i;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (myPieceColor == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //check right
        for (int i = 1, l = NUMBER_COLUMNS - chessPieceSelected % NUMBER_COLUMNS; i < l; i++) {
            int index = chessPieceSelected + i;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (myPieceColor == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        //check up
        for (int i = 1, l = chessPieceSelected / NUMBER_ROWS; i <= l; i++) {
            int index = chessPieceSelected - i * NUMBER_COLUMNS;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (myPieceColor == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
        // check down
        for (int i = 1, l = NUMBER_ROWS - chessPieceSelected / NUMBER_ROWS; i < l; i++) {
            int index = chessPieceSelected + i * NUMBER_COLUMNS;
            if (chessBoardMapPieces[index] == PIECE_VOID) {
                chessValidMove[countValidMove] = index;
                countValidMove++;
            } else {
                if (myPieceColor == getChessColorAtPosition(index)) {
                    break;
                } else {
                    chessValidMove[countValidMove] = index;
                    countValidMove++;
                    break;
                }
            }
        }
    }

    private void generatePawnMove() {
        int countValidMove = 0;
        if (chessPieceSelected - NUMBER_COLUMNS < 0) {
            return;
        }
        if (chessBoardMapPieces[chessPieceSelected - NUMBER_COLUMNS] == PIECE_VOID) {
            chessValidMove[countValidMove] = chessPieceSelected - NUMBER_COLUMNS;
            countValidMove++;
        }
        if (chessBoardMapPieces[chessPieceSelected - NUMBER_COLUMNS - 1] != PIECE_VOID
                && chessPieceSelected % NUMBER_COLUMNS != 0
                && myPieceColor != getChessColorAtPosition(chessPieceSelected - NUMBER_COLUMNS - 1)) {
            chessValidMove[countValidMove] = chessPieceSelected - NUMBER_COLUMNS - 1;
            countValidMove++;
        }
        if (chessBoardMapPieces[chessPieceSelected - NUMBER_COLUMNS + 1] != PIECE_VOID
                && chessPieceSelected % NUMBER_COLUMNS != NUMBER_COLUMNS - 1
                && myPieceColor != getChessColorAtPosition(chessPieceSelected - NUMBER_COLUMNS + 1)) {
            chessValidMove[countValidMove] = chessPieceSelected - NUMBER_COLUMNS + 1;
            countValidMove++;
        }
        if (chessPieceSelected - NUMBER_COLUMNS * 2 < 0) {
            return;
        }
        if (chessBoardMapPieces[chessPieceSelected - NUMBER_COLUMNS * 2] == PIECE_VOID
                && chessBoardMapPieces[chessPieceSelected - NUMBER_COLUMNS] == PIECE_VOID
                && chessPieceSelected / NUMBER_ROWS == 6) {
            chessValidMove[countValidMove] = chessPieceSelected - 2 * NUMBER_COLUMNS;
            countValidMove++;
        }

    }

    private void detectEnterCastle() {
        enteringCastleLeft = false;
        enteringCastleRight = false;
        if (canEnterCastleLeft) {
            int piece = chessBoardMapPieces[srcMoveIndex];
            // Debug.d("check enter left :" + piece);
            //  Debug.d("chess piece select :" + chessPieceSelected);
            if (chessPieceSelected == 58 && piece == KING_WHITE && myPieceColor == PIECE_WHITE) {
                enteringCastleLeft = true;
                Debug.d("trang nhap thanh trai");
            }
            if (chessPieceSelected == 57 && piece == KING_BLACK && myPieceColor == PIECE_BLACK) {
                enteringCastleRight = true;
                Debug.d("den nhap thanh thanh trai");
            }


        }
        if (canEnterCastleRight) {
            int piece = chessBoardMapPieces[srcMoveIndex];
            Debug.d("check enter right :" + piece);
            Debug.d("chess piece select :" + chessPieceSelected);
            if (chessPieceSelected == 62 && piece == KING_WHITE && myPieceColor == PIECE_WHITE) {
                enteringCastleRight = true;
                Debug.d("trang nhap thanh phai");
            }
            if (chessPieceSelected == 61 && piece == KING_BLACK && myPieceColor == PIECE_BLACK) {
                enteringCastleLeft = true;
                Debug.d("den nhap thanh trai");
            }

        }
    }

    private void selectDestPosition() {
        Debug.d("select des");
        boolean isValidMove = false;
        //hop le thi cho di
        for (int i = 0; i < NUMBER_VALID_MOVE; i++) {
            if (chessValidMove[i] == -1) {
                break;
            }
            if (chessPieceSelected == chessValidMove[i]) {
                isValidMove = true;
                //nhap thanh
                detectEnterCastle();
                break;
            }
        }
        isSelectedSrcMove = false;

        // di chuyen quan co
        if (isValidMove) {
            if (!enteringCastleLeft && !enteringCastleRight) {
                int srcColumn = srcMoveIndex % NUMBER_COLUMNS;
                int srcRow = srcMoveIndex / NUMBER_COLUMNS;
                int desColumn = chessPieceSelected % NUMBER_COLUMNS;
                int desRow = chessPieceSelected / NUMBER_COLUMNS;
                doStepMovePiece(playerId, srcRow, srcColumn, desRow, desColumn);
                Request.movePiece(playerId, srcRow, srcColumn, desRow, desColumn);
                if (canEnterCastleLeft || canEnterCastleRight) {
                    checkEnterCastle();
                }
                parent.repaint();
                return;
            }
            if (enteringCastleLeft || enteringCastleRight) {
                int srcColumn = srcMoveIndex % NUMBER_COLUMNS;
                int srcRow = srcMoveIndex / NUMBER_COLUMNS;
                int desColumn = chessPieceSelected % NUMBER_COLUMNS;
                int desRow = chessPieceSelected / NUMBER_COLUMNS;
                if (enteringCastleLeft) {
                    Request.enterBattle(playerId, srcRow, srcColumn, desRow, desColumn, 56 / 8, 56 % 8, 59 / 8, 59 % 8);
                } else if (enteringCastleRight) {
                    Request.enterBattle(playerId, srcRow, srcColumn, desRow, desColumn, 63 / 8, 63 % 8, 61 / 8, 61 % 8);
                }
                initaializeEb(playerId, srcRow, srcColumn, desRow, desColumn);
                parent.repaint();

            }
        }
    }

    private void doStepMovePiece(int id, int srcRow, int srcColumn, int desRow, int desColumn) {
        Debug.d("loai quan move :" + pieceMoveType);
        this.srcMoveIndex = srcRow * NUMBER_COLUMNS + srcColumn;
        this.desMoveIndex = desRow * NUMBER_COLUMNS + desColumn;
        if (isFinishGame()) {
            Request.finishGame(gameTurn);
        }
        initializePieceMove();
    }

    private void initializePieceMove() {
        pieceMoveX = getChessBoxX(srcMoveIndex);
        pieceMoveY = getChessBoxY(srcMoveIndex);
        desMoveX = getChessBoxX(desMoveIndex);
        desMoveY = getChessBoxY(desMoveIndex);
        deltaMoveX = desMoveX - pieceMoveX;
        deltaMoveY = desMoveY - pieceMoveY;
        Debug.d("deltaX :" + deltaMoveX);
        pieceMoveType = chessBoardMapPieces[srcMoveIndex];
        chessBoardMapPieces[srcMoveIndex] = PIECE_VOID;
        gameState = STATE_PIECE_MOVE;
        if (Math.abs(srcMoveIndex - desMoveIndex) >= NUMBER_COLUMNS - 2 || Math.abs(srcMoveIndex - desMoveIndex) <= 2) {
            chessMoveStep = 5;
        } else {
            chessMoveStep = 10;
        }
        parent.repaint();
    }

    private boolean isFinishGame() {
        if (chessBoardMapPieces[desMoveIndex] == KING_WHITE && pieceColorSelect == PIECE_BLACK
                || chessBoardMapPieces[desMoveIndex] == KING_BLACK && pieceColorSelect == PIECE_WHITE) {
            return true;
        }
        return false;
    }

    private void initaializeEb(int id, int srcRow, int srcColumn, int desRow, int desColumn) {
        Debug.d("player id :" + playerId);
        Debug.d("player id :" + id);
        enteringCastleLeft = false;
        enteringCastleRight = false;
        if (myPieceColor == PIECE_WHITE) {
            if (playerId == id) {
                Debug.d("nhap thanh desColum :" + desColumn);
                if (desColumn == 2) {
                    enteringCastleLeft = true;
                    Debug.d("nhap thanh trai ");
                } else if (desColumn == 6) {
                    enteringCastleRight = true;
                    Debug.d("nhap thanh phai ");
                }
                doStepMovePiece(id, srcRow, srcColumn, desRow, desColumn);
            } else {
                Debug.d("nhap thanh desColum :" + desColumn);
                if (desColumn == 2) {
                    enteringCastleLeft = true;
                    Debug.d("nhap thanh trai ");
                } else if (desColumn == 6) {
                    enteringCastleRight = true;
                    Debug.d("nhap thanh phai ");
                }
                doStepMovePiece(id, srcRow, srcColumn, desRow, desColumn);
            }
        } else {
            if (playerId != id) {
                Debug.d("nhap thanh desColum :" + desColumn);
                if (desColumn == 1) {
                    enteringCastleLeft = true;
                    Debug.d("nhap thanh trai ");
                } else if (desColumn == 5) {
                    enteringCastleRight = true;
                    Debug.d("nhap thanh phai ");
                }
                doStepMovePiece(id, srcRow, srcColumn, desRow, desColumn);
            } else {
                Debug.d("nhap thanh desColum :" + desColumn);
                if (desColumn == 1) {
                    enteringCastleLeft = true;
                    Debug.d("nhap thanh trai ");
                } else if (desColumn == 5) {
                    enteringCastleRight = true;
                    Debug.d("nhap thanh phai ");
                }
                doStepMovePiece(id, srcRow, srcColumn, desRow, desColumn);
            }

        }
    }

    private void checkEnterCastle() {
        int piece = pieceMoveType;
        Debug.d("check nhap thanh trai:" + piece + ",src index :" + srcMoveIndex);
        if (srcMoveIndex == 56
                && ((piece == ROCK_BLACK && myPieceColor == PIECE_BLACK) || (piece == ROCK_WHITE && myPieceColor == PAWN_WHITE))) {
            Debug.d("xe trai di chuyen");
            canEnterCastleLeft = false;
        }
        //check nhap thanh phai
        if (srcMoveIndex == 63 && ((piece == ROCK_BLACK && myPieceColor == PIECE_BLACK) || (piece == ROCK_WHITE && myPieceColor == PAWN_WHITE))) {
            Debug.d("xe phai di chuyen");
            canEnterCastleRight = false;
        }


        //check tuong di chuyen
        if ((piece == KING_BLACK && myPieceColor == PIECE_BLACK)
                || (piece == KING_WHITE && myPieceColor == PIECE_WHITE)) {
            Debug.d("tuong di chuyen");
            canEnterCastleLeft = canEnterCastleRight = false;
        }

    }

    private void setPiecePromotion() {
        if (myPieceColor == PIECE_BLACK) {
            switch (promotionIndex) {
                case 0:
                    chessBoardMapPieces[ promotionLocation] = ROCK_BLACK;
                    break;
                case 1:
                    chessBoardMapPieces[ promotionLocation] = KNIGHT_BLACK;
                    break;
                case 2:
                    chessBoardMapPieces[ promotionLocation] = BISHOP_BLACK;
                    break;
                case 3:
                    chessBoardMapPieces[ promotionLocation] = QUEEN_BLACK;
                    break;
            }
            Request.promoteChess(chessBoardMapPieces[ promotionLocation], promotionLocation / 8, promotionLocation % 8);
            isPromotion = false;
            parent.repaint();
            return;
        }
        if (myPieceColor == PIECE_WHITE) {
            switch (promotionIndex) {
                case 0:
                    chessBoardMapPieces[ promotionLocation] = ROCK_WHITE;
                    break;
                case 1:
                    chessBoardMapPieces[ promotionLocation] = KNIGHT_WHITE;
                    break;
                case 2:
                    chessBoardMapPieces[ promotionLocation] = BISHOP_WHITE;
                    break;
                case 3:
                    chessBoardMapPieces[ promotionLocation] = QUEEN_WHITE;
                    break;
            }
            Request.promoteChess(chessBoardMapPieces[ promotionLocation], promotionLocation / 8, promotionLocation % 8);
            isPromotion = false;
            parent.repaint();
        }
    }
    //---------------------------------------------------------------------------

    public void inputKeyCode(int key) {
        chatBox.inputChar(key);
        isShowChatBox = true;
        parent.repaint();
    }

    protected void touchPressedRemain(int x, int y) {
        touchPieceBoard(x, y);
    }

    public void doTouchReleased(int x, int y) {
    }

    public void doTouchDraged(int x, int y) {
    }

    private void touchPieceBoard(int touchX, int touchY) {
        Debug.d("touch piece board");
        for (int i = 0, l = chessBoardMapPieces.length; i < l; i++) {
            int columnIndex = i % NUMBER_ROWS;
            int rowIndex = i / NUMBER_COLUMNS;
            if (Utils.isTouch(chessBoardX + chessBorderWidth + columnIndex * chessBoxWidth,
                    chessBoardY + chessBorderHeight + rowIndex * chessBoxHeight, chessBoxWidth, chessBoxHeight, touchX, touchY)) {
                chessPieceSelected = i;
                doKeyCenter();
                break;
            }
        }

    }
//-------------------------------------------------------------------------

    private void processStepMessage(String[] part) {
        //STEP|ID|srcRow|srcCol|desRow|desCol
        int id = Integer.parseInt(part[1]);
        if (id == playerId && !isViewer) {
            return;
        }
        gameTurn = id;
        int srcRow = Integer.parseInt(part[2]);
        int srcColumn = Integer.parseInt(part[3]);
        int desRow = Integer.parseInt(part[4]);
        int desColumn = Integer.parseInt(part[5]);
        if ((isViewer && playerId != id) || !isViewer) {
            srcRow = NUMBER_COLUMNS - 1 - srcRow;
            desRow = NUMBER_COLUMNS - 1 - desRow;
            srcColumn = NUMBER_COLUMNS - 1 - srcColumn;
            desColumn = NUMBER_COLUMNS - 1 - desColumn;
        }
        doStepMovePiece(id, srcRow, srcColumn, desRow, desColumn);

    }

    private void processEbMessage(String[] part) {
        //STEP|ID|srcRow|srcCol|desRow|desCol
        int id = Integer.parseInt(part[1]);
        gameTurn = id;
        if (id == playerId && !isViewer) {
            return;
        }
        int srcRow = Integer.parseInt(part[2]);
        int srcColumn = Integer.parseInt(part[3]);
        int desRow = Integer.parseInt(part[4]);
        int desColumn = Integer.parseInt(part[5]);
        srcRow = NUMBER_COLUMNS - 1 - srcRow;
        desRow = NUMBER_COLUMNS - 1 - desRow;
        srcColumn = NUMBER_COLUMNS - 1 - srcColumn;
        desColumn = NUMBER_COLUMNS - 1 - desColumn;
        Debug.d("src row :" + srcRow);
        Debug.d("src col :" + srcColumn);
        Debug.d("des row :" + desRow);
        Debug.d("des col :" + desColumn);
        initaializeEb(id, srcRow, srcColumn, desRow, desColumn);
    }

    public void processMessage(String[] part) {
        super.processMessage(part);
        Debug.d("chess process :" + part[0]);
        if (part[0].equals("RE")) {
            gameData.setReArrData(part);
            return;
        }
        if (part[0].equals("STEP")) {
            processStepMessage(part);
            parent.repaint();
            return;
        }
        if (part[0].equals("START")) {
            resetGameForView();
            return;
        }
        if (part[0].equals("USE")) {
            gameData.setNumberPlayerInTable(part);
            return;
        }
        if (part[0].equals("NEXT")) {
            isLoading = false;
            if (gameState != STATE_PIECE_MOVE) {
                nextTurn();
            }
            parent.repaint();
            return;
        }
        if (part[0].equals("UPAS")) {
            gameData.setTablePass(part);
            return;
        }
        if (part[0].equals("RO")) {
            if (isViewer) {
                Request.exitTable();
                isLoading = true;
            } else {
                gameData.setRoArrData(part);
                if (numberPlayers == 1) {
                    showWaitingRoom();
                    isGoBack = true;
                }
            }
            parent.repaint();
            return;
        }


        if (part[0].equals("CHECKMATE")) {
            idCheckMated = Integer.parseInt(part[2]);
            if (playerId == idCheckMated) {
                switchMessengerBox(2, "Chiếu tướng");
                parent.repaint();
            }

            parent.repaint();
            return;
        }
        if (part[0].equals("FINISH")) {
//            Request.finishChessGame(winnerId);
            winnerId = Integer.parseInt(part[1]);
            if (!isViewer) {
                isFinishGame = true;
                parent.repaint();
            } else {
                resultOrder[winnerId] = 0;
                resultOrder[1 - winnerId] = 1;
                isFinishGame = true;
                parent.repaint();
            }
            return;
        }

        if (part[0].equals("SE")) {
            isLoading = false;
            gameData.setNumberPlayerInTable(part);
            showChooseTable();
            isGoBack = true;
            parent.repaint();
            return;
        }
        if (part[0].equals("SM")) {
            gameData.setTableMoneyBet(part);
            return;
        }

        if (part[0].equals("EB")) {
            processEbMessage(part);
            return;
        }
        if (part[0].equals("UPG")) {
            if (gameTurn == playerId) {
                int chessId = Integer.parseInt(part[1]);
                int row = 7 - Integer.parseInt(part[2]);
                int col = 7 - Integer.parseInt(part[3]);
                chessBoardMapPieces[row * 8 + col] = chessId;
                Debug.d("chess iD  :" + chessId);
                Debug.d("row:" + row);
                Debug.d("col :" + col);

                parent.repaint();
            }
            return;
        }
        if (part[0].equals("DRAW")) {
            if (!isViewer) {
                int idAsk = Integer.parseInt(part[1]);
                if (idAsk != playerId) {
                    questionString = "Bạn có chấp nhận cho đối thủ xin hòa ?";
                }
                parent.repaint();
            }
            return;
        }
        if (part[0].equals("LOSE")) {
            int idLose = Integer.parseInt(part[1]);
            winnerId = 1 - idLose;
            if (playerId == winnerId && !isViewer) {
                dialogString = "Đối thủ của bạn đã nhận thua";
            }
            resultOrder[winnerId] = 0;
            resultOrder[1 - winnerId] = 1;
            isFinishGame = true;
            parent.repaint();
            return;
        }
        if (part[0].equals("AD")) {
            int result = Integer.parseInt(part[1]);
            if (isViewer && result == 1) {
                resultOrder[playerId] = 2;
                resultOrder[1 - playerId] = 2;
                isFinishGame = true;
                parent.repaint();
                return;
            }
            if (isLoading) {
                isLoading = false;
                if (result == 0) {
                    dialogString = "Đối thủ không chấp nhận hòa";
                } else {
                    dialogString = "Đối thủ chấp nhận hòa";
                    resultOrder[playerId] = 2;
                    resultOrder[1 - playerId] = 2;
                    isFinishGame = true;
                }

                parent.repaint();
            }
            return;
        }
        if (part[0].equals("CT")) {
            isLoading = false;
            isGoBack = true;
            showWaitingRoom();
            parent.repaint();
        }
        if (part[0].equals("CHAT")) {
            int postId = (Integer.parseInt(part[2]) - playerId);
            if (postId != 0) {
                switchMessengerBox(2, part[1]);
                parent.repaint();
            }
            return;
        }
//        if (part[0].equals("CM")) {
//            if (isFinishGame) {
//                try {
//                    gameData.changeMoney(Integer.parseInt(part[1]), Integer.parseInt(part[2]));
//                } catch (Exception ex) {
//                    ex.printStackTrace();
//                }
//            }
//            return;
//        }
        if (part[0].equals("CM")) {
            try {
                int money = Integer.parseInt(part[2]);
                int id = Integer.parseInt(part[1]);
                int posId = (id - playerId + maxPlayer) % maxPlayer;
                gameData.changeMoney(id, money);
                switchMoneyChange(posId, part[2]);
                //  startTimeChat[posId] = System.currentTimeMillis();
                parent.repaint();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return;
        }

    }

    public void switchMoneyChange(int posId, String text) {
        switch (posId) {
            case 0:
                moneyFlyStrings[0].setText(text, 1, positionX[0], positionY[0]);
                break;
            case 1:
                if (!isViewer) {
                    moneyFlyStrings[1].setText(text, 1, positionX[2], positionY[2]);
                } else {
                    moneyFlyStrings[1].setText(text, 1, positionX[1], positionY[1]);
                }
                break;
//            case 2:
//                moneyFlyStrings[2].setText(text, 1, positionX[2], positionY[2]);
//                break;
//            case 3:
//                moneyFlyStrings[3].setText(text, 1, positionX[3], positionY[3]);
//                break;
        }
        moneyFlyStrings[posId].show(5000);
    }

    private void resetGameForView() {
        isFinishGame = false;
        for (int i = 0; i < 64; i++) {
            chessBoardMapPieces[i] = PIECE_VOID;
        }
        setupChessBoard();
    }
//-------------------------------------------------------------------------

    protected void doSubMenu() {
        switch (subMenu.getSelectedIndex()) {
            case 0:
                //roi ban
                if (isShowSubMenu) {
                    isShowSubMenu = false;
                    Request.exitTable();
                    isLoading = true;
                }
                break;
            case 1://hoa
                isLoading = true;
                Request.askForDraw(playerId);
                isShowSubMenu = false;
                parent.repaint();
                break;
            case 2:
                Request.acceptLose(playerId);
                isShowSubMenu = false;
                parent.repaint();
                //xin thua
                break;
        }
    }

//---------------------------------------------------------------------------------
    public void setPlayerId(int id) {
        this.playerId = id;
    }

    public void setNumberPlayer(int number) {
        this.numberPlayers = number;
    }

    public void setTableHostId(int id) {
        this.tableHostId = id;
    }

    public void setNumberPlayerReady(int number) {
        this.numberPlayerReadys = number;
    }

    public void setMaxPlayer(int number) {
        this.maxPlayer = number;
    }

    public void setGameRule(int gameRule) {
    }

    public void setMyViewId(int id) {
    }
}
